<?php
/**
* oauth.php
*
* Create on 2015-7-7
* Create by TT
*/
namespace haibao\app\data;

class Oauth extends \haibao\app\data\BaseMysql {
    
	public function __construct(){
		parent::__construct('\haibao\app\model\data\TokenInfo');
	}
	
	/**
	 * 从redis中取出token
	 */
	public function getToken($key){
		$cache = new \haibao\app\cache\Oauth();
		return $cache->getToken($key);
	}
	
	/**
	 * 把token写入redis中，2小时后过期
	 */
	public function setToken($appId, $appSecret, $appType,$signature = ''){
		$cache = new \haibao\app\cache\Oauth();
		$token = sha1( $appId . $appSecret . $appType . $signature . time() );
		$cache->setToken($token, array('Token'=>$token,'AppId'=>$appId,'AppSecret'=>$appSecret,'AppType'=>$appType));
		
		return $token;
	}
}